import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';

class SPUtils {
  SPUtils._internal();
  static SharedPreferences _spf;
  static Future<SharedPreferences> init() async {
    if (_spf == null) {
      _spf = await SharedPreferences.getInstance();
    }
    return _spf;
  }

  ///主题
  static Future<bool> saveThemeIndex(int value) {
    return _spf.setInt('key_theme_color', value);
  }

  static int getThemeIndex() {
    if (_spf.containsKey('key_theme_color')) {
      return _spf.getInt('key_theme_color');
    }
    return 0;
  }

  ///语言
  static Future<bool> saveLocale(String locale) {
    if(locale==null){
	  return _spf.remove('key_locale');
	}else{
      return _spf.setString('key_locale', locale);
	}
  }

  static String getLocale() {
    return _spf.getString('key_locale');
  }
}
